package zhh.tangbao.system.utils;

import org.springframework.stereotype.Component;

/**
 * 2022/11/10
 * @author 粥灰灰
 * @version 1.0
 * 每次获取接口接收到请求的时间戳，用于计算接口响应耗时
 */

@Component
public class SystemTimeHolderUtil {
    private final ThreadLocal<Long> local = new ThreadLocal<>();

    public void setCurrentTime() {
        local.set(System.currentTimeMillis());
    }

    public long getTime() {
        return local.get();
    }

    public long getCurrentConsuming() {
        Long start = local.get();
        return System.currentTimeMillis() - start;
    }
}
